<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%category}}".
 *
 * @property integer $id
 * @property string $category
 * @property string $desc
 * @property integer $created_at
 * @property integer $updated_at
 */
class Category extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%category}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['created_at', 'updated_at'], 'integer'],
            [['category', 'desc'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'category' => '类别',
            'desc' => '类别描述',
            'created_at' => '添加时间',
            'updated_at' => '更新时间',
        ];
    }

    /*
     * 获取以主键id为下标的分类数组
     */
    public static function getCateList()
    {
        $list = static::find()->select(['category','id'])->asArray()->all();
        if(!empty($list)){
            $list = array_column($list, 'category', 'id');
        }
        return $list;
    }
}
